package com.lichongbing.lyoggl.controller;

import com.alibaba.fastjson.JSONObject;
import com.lichongbing.lyoggl.service.LyogglUsersService;
import com.lichongbing.lyoggl.service.VflagsService;
import com.lichongbing.lyoggl.utils.JwtTokenUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lichongbing
 * @version 1.0.0
 * @createdate 2022/4/18 7:20 下午
 * @description: TODO
 */
@Slf4j
@RestController
@RequestMapping("/vtags")
public class VflagsController {
    @Autowired
    private VflagsService vflagsService;
    @Autowired
    private LyogglUsersService lyogglUsersService;

    /**
     * 查询进度列表
     * @param request
     * @return
     */
    @PostMapping("/findAll")
    public JSONObject getTagsByUserId(HttpServletRequest request){
        JSONObject jsonObject = new JSONObject();
        String token = request.getHeader("token");
        boolean expiration = JwtTokenUtils.isExpiration(token);
        if (expiration == false){
            String userId = JwtTokenUtils.getUserid(token);
            boolean flag = lyogglUsersService.isToken(userId);
            if(flag) {
            jsonObject.put("data",vflagsService.findAll(userId));
            jsonObject.put("code",200);
            jsonObject.put("msg", "查询成功");
            return jsonObject;}else {
                jsonObject.put("code",402);
                jsonObject.put("msg","token无效");
                return jsonObject;
            }
        }else {
            jsonObject.put("code",401);
            jsonObject.put("msg", "token过期");
            return jsonObject;
        }

    }






}
